<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ name: 'welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-row>
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="queryInfo.query">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <el-table :data="orderList" style="width: 100%" border stripe>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column prop="order_id" label="订单编号"> </el-table-column>
        <el-table-column prop="order_price" label="订单价格"> </el-table-column>
        <el-table-column prop="order_pay" label="是否付款">
          <template v-slot="{ row }">
            <el-tag type="success" v-if="row.order_pay === 1">已付款</el-tag>
            <el-tag type="warning" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"> </el-table-column>
        <el-table-column prop="create_time" label="下单时间">
          <template v-slot="{ row }">
            {{ row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template>
            <el-button
              class="el-icon-edit"
              type="primary"
              size="mini"
              @click="positionShow"
            ></el-button>
            <el-button
              class="el-icon-location"
              type="success"
              size="mini"
              @click="progressShow"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 15]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
    <!-- 地点对话框 -->
    <el-dialog
      title="修改地址"
      :visible.sync="positionDialogVisible"
      width="50%"
      @close="editDialogClosed"
    >
      <el-form
        :model="editPositionForm"
        :rules="editPositionFormRules"
        ref="editPositionFormRef"
        label-width="100px"
      >
        <el-form-item label="省市区/县" prop="cityLocal">
          <el-cascader
            v-model="editPositionForm.cityLocal"
            :options="CityData"
            :props="cityOptions"
            @change="handleChange"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="detailLocal">
          <el-input v-model="editPositionForm.detailLocal"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="positionDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="positionDialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 物流进度对话框 -->
    <el-dialog
      title="物流进度"
      :visible.sync="progressDialogVisible"
      width="50%"
    >
      <span>这是一段信息</span>
    </el-dialog>
  </div>
</template>

<script>
import { getOrderListAPI } from '@/api'
import CityData from './citydata'
export default {
  name: 'OrderList',
  data() {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      orderList: [],
      total: 0,
      CityData,
      positionDialogVisible: false,
      editPositionForm: {
        cityLocal: [],
        detailLocal: ''
      },
      cityOptions: {
        value: 'value',
        label: 'label',
        children: 'children',
        expandTrigger: 'hover'
      },
      editPositionFormRules: {
        cityLocal: [
          { required: true, message: '请输入省市区/县', trigger: 'blur' }
        ],
        detailLocal: [
          { required: true, message: '请输入详细地址', trigger: 'blur' }
        ]
      },
      progressDialogVisible: false
    }
  },
  created() {
    this.loadingOrderList()
  },
  methods: {
    async loadingOrderList() {
      try {
        const { data } = await getOrderListAPI(this.queryInfo)
        if (data.meta.status !== 200) {
          return this.$message.error('获取订单列表数据失败')
        }
        // console.log(data)
        this.total = data.data.total
        this.orderList = data.data.goods
        this.$message.success('获取订单列表数据成功')
      } catch (error) {
        this.$message.error('获取订单列表数据失败')
      }
    },
    // 处理每页数量改变
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize
      this.loadingOrderList()
    },
    // 处理页数改变
    handleCurrentChange(newPage) {
      this.queryInfo.pagenum = newPage
      this.loadingOrderList()
    },
    // 展示地点
    positionShow() {
      this.positionDialogVisible = true
    },
    // 级联选择框改变
    handleChange() {},
    // 关闭对话框
    editDialogClosed() {
      this.$refs.editPositionFormRef.resetFields()
    },
    // 物流进度
    async progressShow() {
      try {
        // 接口不对
        // const { data } = await getGoodsProgressAPI()
        // console.log(data)
      } catch (error) {
        this.$message.error('获取物流进度数据失败')
      }
      this.progressDialogVisible = true
    }
  }
}
</script>

<style scoped lang="less">
.el-cascader {
  width: 100%;
}
</style>
